<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="HandheldFriendly" content="true" />
    <meta name="MobileOptimized" content="320" />
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/ai-dog.css">
    <link rel="stylesheet" href="./css/jiazai.css">
    <title>智能搬砖</title>
</head>

<body>
    <div id='app'>

        <!-- 加载中动画 -->
        <div class='jiazai' v-if='jiazai'>
            <img src="./img/jia-ani.gif" width="50px" height="50px">
        </div>
        <!-- 加载中动画 -->

        <!-- 开启智能狗弹窗 -->
        <div id='mask' @click='offAiDog=false;getData()' v-if='offAiDog'></div>
        <transition enter-active-class='animated fadeIn' leave-active-class='animated fadeOut'>
            <div class='fixed-ai-wrap' v-if='offAiDog' @click='offAiDog=false;getData()'>
                <div class='fixed-center' @click.stop=''>
                    <div class='title-hea'>
                        <span style="opacity:0;">1</span>
                        <span>开启AI智能搬砖</span>
                        <img @click='offAiDog=false;getData()' src="./img/close.svg" width="24px" height="24px">
                    </div>
                    <div v-if='parseFloat(openDogData.financing)>0' style="padding:5px 0;font-size:14px;line-height:20px;color: #999;">
                        立刻开启智能搬砖，立享{{openDogData.financing}}{{openDogData.coins_name}}({{openDogData.coins_ename}})理财金加成
                    </div>
                    <div v-else style="padding:5px 0;font-size:14px;line-height:20px;">
                        目前可开启数量：<span v-text='_toFixed(openDogData.user_have_money,6)'>5</span><span v-text='openDogData.coins_ename'>ETH</span>
                    </div>
                    <div class='num-huansuan' v-if='num'>
                        <div>
                            <input type="text" readonly v-model='num' style="width:100%;">
                            <span v-text='openDogData.coins_ename'>ETH</span>
                        </div>
                        <span>=</span>
                        <div>
                            <input type="text" readonly style="width:100%;" :value='_toFixed(openDogData.coins_price*parseFloat(num),6)'>
                            <span>USDT</span>
                        </div>
                    </div>
                    <input type="text" placeholder="请输入开启数量" v-model='num'>
                    <button @click='fastConve'>确认</button>
                </div>
            </div>
        </transition>
        <!-- 开启智能狗弹窗 -->

        <!-- 闪兑--自定义键盘 -->
        <div id='mask' @click='oofTransiaction=false;offKeyWord=false;getData()' v-if='oofTransiaction'></div>
        <transition enter-active-class='animated fadeIn' enter-active-class='animated fadeOut'>
            <div class='transaction-input-wrap' v-if='oofTransiaction' @click='oofTransiaction=false;offKeyWord=false;getData()'>
                <div class='trans-pass-content' @click.stop=''>
                    <div class='trans-hea'>
                        <span style="opacity:0">1</span>
                        <span>输入交易密码</span>
                        <img src="./img/close.svg" width="27px" height="27px" @click='oofTransiaction=false;offKeyWord=false;getData()'>
                    </div>
                    <div class='trans-num' @click='openKeyWord'>
                        <span ref='input1'></span>
                        <span ref='input2'></span>
                        <span ref='input3'></span>
                        <span ref='input4'></span>
                        <span ref='input5'></span>
                        <span ref='input6'></span>
                    </div>
                    <button class='btn-com' @click='clkSubmit'>确认提交</button>
                </div>
            </div>
        </transition>
        <transition enter-active-class='animated fadeInUp' enter-active-class='animated fadeOutDown'>
            <div class="keyborad" v-if='offKeyWord'>
                <ul>
                    <li>
                        <dt @click="clkValue('1')">1</dt>
                        <dt @click="clkValue('2')">2</dt>
                        <dt @click="clkValue('3')">3</dt>
                    </li>
                    <li>
                        <dt @click="clkValue('4')">4</dt>
                        <dt @click="clkValue('5')">5</dt>
                        <dt @click="clkValue('6')">6</dt></li>
                    <li>
                        <dt @click="clkValue('7')">7</dt>
                        <dt @click="clkValue('8')">8</dt>
                        <dt @click="clkValue('9')">9</dt></li>
                    <li>
                        <dt @click="clkValue('.')">.</dt>
                        <dt @click="clkValue('0')">0</dt>
                        <dt @click="hide" class="iconfont icon-jianpanxiahua" style="display:flex; justify-content: center; align-item:center;">
                            <img src="./img/key-down.svg">
                        </dt>
                    </li>
                </ul>
                <div id="del" @click="del" class="del iconfont icon-jianpan_shanchu" style="display:flex; justify-content: center; align-item:center;">
                    <img src="./img/key-del.svg">
                </div>
                <div id="btn" class="button" @click="clkSubmit">
                    提交
                </div>
            </div>
        </transition>
        <!-- 闪兑--自定义键盘 -->

        <div class='notice-hea'>
            <div>
                <img @click='close' src="./img/right-black.svg" width="20px" height="20px">
                <span>智能搬砖</span>
            </div>
            <img @click='_openHref("open-dog-list.html","openDogList")' src="./img/dog-bill.png" width="20px">
        </div>
        <div class='dog-list-wrap'>
            <div v-for="(val,index) in dataList" :key='index' style="margin-bottom:15px;">
                <div class='dog-list'>
                    <div class='dog-left'>
                        <img @click='moreInfo(val)' :src="val.coins_logo?HTTP+val.coins_logo:'./img/timg.png'" width="50px" height="50px">
                        <div>
                            <h1 v-text='val.coins_ename'>BTC</h1>
                            <p v-text='val.coins_ename2'>BitCoin</p>
                            <p>
                                <span>当前搬砖余额:</span>
                                <span v-text='_toFixed(val.bzmoney,6)'>0.00</span>
                            </p>
                        </div>
                    </div>
                    <div class='open-btn' @click='changeSwitch(val)' v-text='val.offSwitch?"点击关闭搬砖":"点击开启搬砖"'>
                        开启搬砖
                    </div>
                </div>
                <div class='more-go' @click='moreInfo(val)'>
                    <div>
                        <img style="margin-right:8px;" src="./img/time-share.svg" width="15px" height="15px">
                        <span>每天12:00-16:00为结算时间</span>
                    </div>
                    <div>
                        <span>更多</span>
                        <img src="./img/left.svg" width="22px" height="22px">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="js/comm.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/back.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/base64.js"></script>
    <!-- <script src="js/el/index.js"></script> -->
    <script type="text/javascript" charset="utf-8">
        var app = new Vue({
            el: '#app',
            data: {
                //加载动画
                jiazai: false,
                //智能狗列表
                dataList: [{
                    coins_ename: '',
                    coins_ename2: '',
                    offSwitch: false,
                }],
                //将要开启/关闭的智能狗数据
                openDogData: {},
                //将要开启的智能狗的数量
                num: '',
                //开启智能狗输入数量弹窗
                offAiDog: false,
                //控制自定义键盘弹窗(是输入交易密码的弹窗)
                oofTransiaction: false,
                //控制自定义的键盘
                offKeyWord: false,
                //输入的6位数交易密码
                transPass: [],
            },
            created: function() {
                this.getData();
            },
            watch: {
                oofTransiaction: function(val) {
                    if (!val) {
                        this.transPass = [];
                    }
                },
            },
            methods: {
                close: function() {
                    var web = plus.webview.currentWebview();
                    web.close('none');
                },
                //得到智能狗列表
                getData: function() {
                    this.num = 0;
                    this.jiazai = true;
                    var This = this;
                    var user=JSON.parse(localStorage.getItem('user'));
                    _post(ZINENGGOU, {
                        userid: user.userid,
                        session: user.session
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            data.back.map(function(val) {
                                if (val.is_open == 2) {
                                    return val.offSwitch = true;
                                } else {
                                    return val.offSwitch = false;
                                }
                            });
                            This.dataList = data.back;
                        } else {
                            _toast(data.msg);
                        }
                    });
                },
                //打开 或者 关闭开关
                changeSwitch: function(val) {
                    this.openDogData = val;
                    if (!val.offSwitch) {
                    	//将要打开智能狗
                        this.openDogData.type = 'open';
                        this.openDogData = val;
                        this.offAiDog = true;
                    } else {
                    	var currTime=Date.parse(new Date())/1000;
                    	var se=currTime-Number(val.zngtime);
                    	if(se<2419200){
                    		var This=this;
	                    	plus.nativeUI.confirm('开启未满28天手续费5%是否确定申请关闭 ？', function(ev) {
		                       if (ev.index == 0) {
		                            This.openDogData.type = 'close';
		                    		This.oofTransiaction = true;
		                    		var hei = ($(document).height() - 200) / 2;
		                    		setTimeout(function() {
		                    		    $('.transaction-input-wrap').css('transform', "translateY(" + hei + "px)");
		                    		}, 20);
		                       }
		                   });
                    	}else{
                    		this.openDogData.type = 'close';
                    		this.oofTransiaction = true;
                    		var hei = ($(document).height() - 200) / 2;
                    		setTimeout(function() {
                    		    $('.transaction-input-wrap').css('transform', "translateY(" + hei + "px)");
                    		}, 20);
                    	}
                    }
                },
                //更多信息
                moreInfo: function(val) {
                    var json = JSON.parse(JSON.stringify(val));
                    if (val.coins_logo) {
                        delete json.coins_logo;
                    }
                    var web = _openHref('more-zin-info.html', 'moreZinInfo');
                    setTimeout(function() {
                        web.evalJS("send('" + JSON.stringify(json) + "')");
                    }, 200);
                },
                //打开输入交易密码框
                fastConve: function() {
                    if (String(parseFloat(this.num)).length != this.num.length) {
                        _toast('请输入正确的数量');
                        this.num = 0;
                        return;
                    }
                    var This = this;
                    setTimeout(function() {
                        This.offAiDog = false;
                        This.oofTransiaction = true;
                        var hei = ($(document).height() - 200) / 2;
                        setTimeout(function() {
                            $('.transaction-input-wrap').css('transform', "translateY(" + hei + "px)");
                        }, 20);
                    }, 800);
                },
                //打开自定义键盘
                openKeyWord: function() {
                    if (this.offKeyWord) {
                        return;
                    }
                    var hei = $(document).height() - 470;
                    this.offKeyWord = true;
                    $('.transaction-input-wrap').css('transform', "translateY(" + hei + "px)");
                },
                //输入交易密码的值
                clkValue: function(val) {
                    if (val == '.') {
                        return;
                    }
                    var len = this.transPass.length;
                    if (len == 6) {
                        this.clkSubmit();
                        return;
                    }
                    var input = 'input' + (len + 1);
                    this.transPass.push(val);
                    this.$refs[input].innerHTML = val;
                    if (this.transPass.length == 6) {
                        this.clkSubmit();
                    }
                },
                //删除一个数值
                del: function() {
                    if (this.transPass.length == 0) {
                        return;
                    }
                    var len = this.transPass.length;
                    var input = 'input' + len;
                    this.$refs[input].innerHTML = '';
                    this.transPass.pop();
                },
                //自定义键盘的提交
                clkSubmit: function() {
                    if (this.transPass.length != 6) {
                        _toast('请输入正确的密码');
                        return;
                    }
                    this.sendOpen();
                },
                //发送开启智能狗请求
                sendOpen: function() {
                    var user = JSON.parse(localStorage.getItem('user'));
                    console.log(JSON.stringify(this.openDogData))
                    var send = {
                        session: user.session,
                        userid: user.userid,
                        coinsid: this.openDogData.id,
                        num: this.num,
                        pin: this.transPass.join('')
                    };
                    var url = ZINEGNGOU_OPEN;
                    if (this.openDogData.type == 'close') {
                        delete send.num;
                        url = ZNG_CLOSE;
                    }
                    var This = this;
                    this.jiazai = true;
                    console.log(JSON.stringify(send))
                    _bas64Post(url, send, function(data) {
                        _toast(data.msg);
                        if (data.status == 1) {
                            This.oofTransiaction = This.offKeyWord = This.offAiDog = false;
                            This.getData();
                        } else {
                            This.jiazai = false;
                        }
                    });
                },
                //隐藏自定义键盘
                hide: function() {
                    this.offKeyWord = false;
                },
            }
        });
       
    </script>
</body>

</html>